import request from "../utils/request.js"

export default {

    /**
     * 根据ID查询user
     * @param userId
     * @return {Promise | Promise<unknown>}
     */
     findUserById: (userId) => {
        return request.get(`/user/${userId}`)
    }
    /**
     * 根据ID，手机号，邮箱，username，昵称
     * @param keyword
     * @param flag
     * @return {Promise<unknown>}
     */
    , searchContact: (keyword,flag="") => {
        return request.get(`/user/search?kw=${keyword}&flag=${flag}`)
    }

    /**
     * 根据ID查询群组
     */
    ,findChatGroupByRelId: (relId) => {
        return request.get(`/chat/group/${relId}`)
    }

    , applyFriend: (userId) => {
        return request.post(`/contact/apply/${userId}`)
    }

    , deleteFriend: (userId) => {
        return request.delet(`/contact/friend/${userId}`)
    }

    , agreedFriend: (userId) => {
        return request.put(`/contact/agreed/${userId}`)
    }

    , refuseFriend: (userId) => {
        return request.put(`/contact/refuse/${userId}`)
    }

    , addToBlack: (userId) => {
        return request.post(`/contact/black/${userId}`)
    }

    , removeFromBlack: (userId) => {
        return request.delet(`/contact/black/${userId}`)
    }

    ,findConvIdsByChatuser: (chatuser)=> {
        return request.get(`/chat/conversations/${chatuser}`)
    }
    //获取聊天信息流
    ,findConversationById: (convId)=> {
        return request.get(`/chat/conversation/${convId}`)
    }
    /**
     * 获取联系人列表
     */
    ,findContactList: () => {
        return request.get(`/contact/list/current`)
    }

    /**
     * 获取聊天列表
     */
    ,findChatterRelationList: () => {
        return request.get(`/chat/chatters/current`)
        // return new Promise((resolve, reject) => {
        //     resolve({
        //         ok:true,
        //         msg: "",
        //         data: []
        //     })
        // });
    }
    /**
     * 获取群组列表
     */
     ,findChatGroupList: () => {
        return request.get(`/chat/group/list`)
        // return new Promise((resolve, reject) => {
        //     resolve({
        //         ok:true,
        //         msg: "",
        //         data: []
        //     })
        // });
    }

    /**
     * 获取好友申请列表
     */
    ,findApplyList: () => {
        return request.get(`/contact/apply/list`)
    }

    /**
     * 清空好友申请列表
     * @returns {Promise | Promise<unknown>}
     */
    ,clearApplyAll:() => {
        return request.post(`/contact/apply-clear/all`)
    }
    /**
     * 清空好友申请列表
     * @returns {Promise | Promise<unknown>}
     */
    ,clearApplyByUid:(uid) => {
        return request.post(`/contact/apply-remove/${uid}`)
    }

    , findMessages: (chatId,isGroup,msgId) => {
        return request.get(`/chat/messages/current`,{chatId:chatId,isGroup:(!!isGroup),before:(msgId?msgId:0)})
    }

    /**
     * 编辑群信息
     */
    , editGroupInfo: (data)=>{
        return request.put(`/chat/group/edit`,data)
    }
}